package com.spzx.product;

import com.spzx.common.security.annotation.EnableCustomConfig;
import com.spzx.common.security.annotation.EnableRyFeignClients;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.mapper.ProductSkuMapper;
import jakarta.annotation.Resource;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.List;

/**
 * @author Haoran Sun
 * @since 2024/07/14
 */

@SpringBootApplication
@EnableRyFeignClients
@EnableCustomConfig
public class SpzxProductApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(SpzxProductApplication.class, args);
        System.out.println("                   _ooOoo_");
        System.out.println("                  o8888888o");
        System.out.println("                  88\" . \"88");
        System.out.println("                  (| -_- |)");
        System.out.println("                  O\\  =  /O");
        System.out.println("               ____/`---'\\____");
        System.out.println("             .'  \\\\|     |//  `.");
        System.out.println("            /  \\\\|||  :  |||//  \\");
        System.out.println("           /  _||||| -:- |||||-  \\");
        System.out.println("           |   | \\\\\\  -  /// |   |");
        System.out.println("           | \\_|  ''\\---/''  |   |");
        System.out.println("           \\  .-\\__  `-`  ___/-. /");
        System.out.println("         ___`. .'  /--.--\\  `. . __");
        System.out.println( "      .\"\" '<  `.___\\_<|>_/___.'  >'\"\".");
        System.out.println("     | | :  `- \\`.;`\\ _ /`;.`/ - ` : | |");
        System.out.println("     \\  \\ `-.   \\_ __\\ /__ _/   .-` /  /");
        System.out.println("======`-.____`-.___\\_____/___.-`____.-'======");
        System.out.println("                   `=---='");
        System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
        System.out.println("               佛祖保佑       永无BUG");
    }


    @Resource
    private RedissonClient redissonClient;

    @Resource
    private ProductSkuMapper productSkuMapper;

    /**
     * Springboot应用初始化后会执行一次该方法
     *
     * @param args
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {
        //初始化布隆过滤器
        RBloomFilter<Object> bloomFilter = redissonClient.getBloomFilter("sku:bloom:filter");
        //设置数据规模 误判率 预计统计元素数量为100000，期望误差率为0.01
        bloomFilter.tryInit(100000, 0.01);

        //测试使用，快速自动加入
        List<ProductSku> productSkuList = productSkuMapper.selectList(null);
        productSkuList.forEach(item -> {
            bloomFilter.add(item.getId());
        });
    }




}
